<script type="text/javascript">
	var url;
	var LODOP;
	function newOrderDinner(){
		$('#dlg').dialog('open').dialog('setTitle','添加申请单');
		$('#fm').form('clear');
		url = '<?php echo url('dinner','add')?>';
	}
	
	function editOrderDinner(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$('#dlg').dialog('open').dialog('setTitle','编辑申请单');
			$('#fm').form('load',row);
			url = '<?php echo url('dinner','update')?>&id='+row.id;
		}
	}
	
	function saveOrderDinner(){
		$('#fm').form('submit',{
			url: url,
			onSubmit: function(){
				return $(this).form('validate');
			},
			success: function(result){
				var result = eval('('+result+')');
				if (result.success){
					$('#dlg').dialog('close');		// close the dialog
					$('#dg').datagrid('reload');	// reload the user data
				} else {
					$.messager.show({
						title: '错误',
						msg: result.msg
					});
				}
			}
		});
	}
	
	function removeOrderDinner(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$.messager.confirm('确认','一定要取消该申请单吗?',function(r){
				if (r){
					$.post('<?php echo url('dinner','del')?>',{id:row.id},function(result){
						if (result.success){
							$('#dg').datagrid('reload');	// reload the user data
						} else {
							$.messager.show({	// show error message
								title: '错误',
								msg: result.msg
							});
						}
					},'json');
				}
			});
		}
	}
	
	$(function(){
		$('#dg').datagrid({
			view: detailview,
			detailFormatter:function(index,row){
				return '<div class="ddv"><table>' +
				'<tr><td style="border:0; padding:2px 8px;">备注: </td>' +
				'<td style="border:0; padding:2px 8px;">' + row.comment + '</td></tr>' +
				'</table></div>';
			},
		});
	});
	
	function doSearchDate(){   
		$('#dg').datagrid('load',{   
			date1: $('#dd1').datebox("getValue"),   
			date2: $('#dd2').datebox("getValue")
		}); 
	}
	
	function doSearchNum(){
		$('#dg').datagrid('load',{
			num: $('#num').val()
		});
	}
	
	function printOrderDinner(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			myPreview(row);
		}
	}
	
	function myPreview(row) {		
		CreatePrintPage(row);
		//LODOP.PRINT_DESIGN();
		LODOP.PREVIEW();
	};
	
	function CreatePrintPage(row) {
		d_arr=row.date.split("-");
		if(row.amount_real==0)row.amount_real='';
		LODOP=getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));  
		LODOP.PRINT_INIT("用餐申请单");
		LODOP.SET_PRINT_PAGESIZE(1,2100,1200,"CreateCustomPage");
		LODOP.SET_PRINT_STYLE("FontColor","#000000");
		LODOP.SET_PRINT_STYLE("FontName","微软雅黑");
		LODOP.SET_PRINT_STYLE("FontSize",12);
		LODOP.SET_PRINT_STYLE("Alignment",2);
		
		LODOP.ADD_PRINT_TEXT(25,20,754,35,"菱塘回族乡政府接待用餐安排通知单");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",18);
		
		LODOP.ADD_PRINT_TEXT(65,624,30,25,"№:");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.ADD_PRINT_TEXT(65,654,120,25,row.num);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		
		LODOP.ADD_PRINT_BARCODE(375,20,50,50,"QRCode",row.num);
		LODOP.SET_PRINT_STYLEA(0,"Color","#0000FF");
		LODOP.SET_PRINT_STYLEA(0,"QRCodeVersion",1);
		LODOP.SET_PRINT_STYLEA(0,"NotOnlyHighPrecision",true);
		
		LODOP.ADD_PRINT_TEXT(110,20,150,30,"：");
		LODOP.SET_PRINT_STYLEA(0,"Alignment",3);
		LODOP.ADD_PRINT_RECT(130,20,150,1,0,1);
		
		LODOP.ADD_PRINT_TEXT(160,20,110,30,"根据工作需要");
		LODOP.SET_PRINT_STYLEA(0,"Alignment",1);
		LODOP.ADD_PRINT_TEXT(160,130,200,30,row.visitor);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_RECT(180,130,200,1,0,1);
		
		LODOP.ADD_PRINT_TEXT(160,330,80,30,"来人，由");
		LODOP.ADD_PRINT_TEXT(160,410,364,30,row.department+"，"+row.user);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_RECT(180,410,364,1,0,1);
		
		LODOP.ADD_PRINT_TEXT(210,20,110,30,"负责接待，共");
		LODOP.SET_PRINT_STYLEA(0,"Alignment",1);
		LODOP.ADD_PRINT_TEXT(210,130,60,30,row.hc);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_RECT(230,130,60,1,0,1);
		
		LODOP.ADD_PRINT_TEXT(210,190,130,30,"人，请给予安排");
		LODOP.ADD_PRINT_TEXT(210,320,50,30,row.classname);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_RECT(230,320,50,1,0,1);
		
		LODOP.ADD_PRINT_TEXT(210,370,25,30,"，");
		LODOP.ADD_PRINT_TEXT(210,395,39,30,row.tc);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_RECT(230,395,39,1,0,1);
		
		LODOP.ADD_PRINT_TEXT(210,434,145,30,"桌，每桌菜金标准");
		LODOP.ADD_PRINT_TEXT(210,579,100,30,row.price);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_RECT(230,579,100,1,0,1);
		
		LODOP.ADD_PRINT_TEXT(210,679,95,30,"元，酒每瓶");
		LODOP.ADD_PRINT_TEXT(260,20,100,30,row.drinks_price);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_RECT(280,20,100,1,0,1);
		
		LODOP.ADD_PRINT_TEXT(260,120,50,30,"元。");
		LODOP.ADD_PRINT_TEXT(310,20,60,30,"备注：");
		LODOP.SET_PRINT_STYLEA(0,"Alignment",1);
		LODOP.ADD_PRINT_TEXT(310,80,694,30,row.comment);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.SET_PRINT_STYLEA(0,"Alignment",1);
		
		
		LODOP.ADD_PRINT_TEXT(360,524,210,30,"菱塘回族乡人民政府办公室");
		LODOP.ADD_PRINT_TEXT(400,520,50,25,"日期：");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.ADD_PRINT_TEXT(400,569,50,25,d_arr[0]);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_TEXT(400,619,25,25,"年");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.ADD_PRINT_TEXT(400,644,25,25,d_arr[1]);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_TEXT(400,669,25,25,"月");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.ADD_PRINT_TEXT(400,694,25,25,d_arr[2]);
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
		LODOP.SET_PRINT_STYLEA(0,"FontColor","#0000FF");
		LODOP.ADD_PRINT_TEXT(400,719,25,25,"日");
		LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
	};
</script>

<table id="dg" title="用餐申请与打印" class="easyui-datagrid"
		url="<?php echo url('dinner','list')?>"
		toolbar="#toolbar" pagination="true"
		rownumbers="true" fitColumns="true" fit="true" singleSelect="true">
	<thead>
		<tr>
			<th field="num" width="70">编号</th>
			<th field="date" width="50">日期</th>
			<th field="visitor" width="100">来访单位</th>
			<th field="department" width="100">接待部门</th>
			<th field="user" width="50">接待人</th>
			<th field="classname" width="50">餐</th>
			<th field="hc" width="50">人数</th>
			<th field="tc" width="50">桌数</th>
			<th field="price" width="50">菜金标准</th>
			<th field="drinks_price" width="50">酒水标准</th>
		</tr>
	</thead>
</table>
<div id="toolbar" style="padding:5px;height:auto">
	<div style="margin-bottom:5px">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newOrderDinner()">添加申请单</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editOrderDinner()">编辑申请单</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeOrderDinner()">取消申请单</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-print" plain="true" onclick="printOrderDinner()">打印申请单</a>
	</div>
	<div>
		<label>按单据编号：</label><input id="num" />
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearchNum()">搜索</a>
	</div>
	<div>
		<label>按日期范围：</label><input id="dd1" name="dd1" class="easyui-datebox" /><label>至</label><input id="dd2" name="dd2" class="easyui-datebox" />
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearchDate()">搜索</a>
	</div>
</div>

<div id="dlg" class="easyui-dialog" style="width:400px;height:480px;padding:10px 20px"
		closed="true" buttons="#dlg-buttons">
	<div class="ftitle">申请单信息</div>
	<form id="fm" method="post" novalidate>
		<div class="fitem">
			<label>日期:</label>
			<input name="date" class="easyui-datebox">
		</div>
		<div class="fitem">
			<label>来访单位:</label>
			<select class="easyui-combotree" url="<?php echo url('dinner','comboboxvisitor')?>" name="vid" style="width:156px;"/>
			<input name="visitor" type="hidden">
		</div>
		<div class="fitem">
			<label>接待部门:</label>
			<select class="easyui-combotree" url="<?php echo url('dinner','comboboxdepartment')?>" name="did" style="width:156px;"/>
			<input name="department" type="hidden">
		</div>
		<div class="fitem">
			<label>接待人:</label>
			<select class="easyui-combotree" url="<?php echo url('dinner','comboboxuser')?>" name="uid" style="width:156px;"/>
			<input name="user" type="hidden">
		</div>
		<div class="fitem">
			<label>餐:</label>
			<select class="easyui-validatebox" name="class">
			<option value="0">早餐</option>
			<option value="1">午餐</option>
			<option value="2">晚餐</option>
			</select>
		</div>
		<div class="fitem">
			<label>人数:</label>
			<input name="hc" class="easyui-validatebox" required="true">
		</div>
		<div class="fitem">
			<label>桌数:</label>
			<input name="tc" class="easyui-validatebox" required="true">
		</div>
		<div class="fitem">
			<label>菜金标准:</label>
			<input name="price" class="easyui-validatebox" required="true">
		</div>
		<div class="fitem">
			<label>酒水标准:</label>
			<input name="drinks_price" class="easyui-validatebox" required="true">
		</div>
		<div class="fitem">
			<label>备注:</label>
			<textarea name="comment" class="easyui-validatebox"></textarea>
		</div>
	</form>
</div>
<div id="dlg-buttons">
	<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveOrderDinner()">保存</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>